package com.example.geoquiz;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

public class AddActivity extends AppCompatActivity {

    private static final String ADD_PROBLEM_ANSWER ="com.example.geoquiz.add_problem_answer";
    private Button mYesButton;
    private Boolean setAnswerButton;
    String inputtext;
    private RadioGroup radiogroup;
    private RadioButton true_radio,false_radio;

    public static Question wasAddShown(Intent result) {
        return (Question) result.getSerializableExtra(ADD_PROBLEM_ANSWER);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);

        true_radio=(RadioButton)findViewById(R.id.true_radio);
        false_radio=(RadioButton)findViewById(R.id.false_radio);
        radiogroup=(RadioGroup)findViewById(R.id.radiogroup);
        radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup group, int checkId) {
                switch (checkId){
                    case R.id.true_radio:
                        setAnswerButton = true;
                        break;
                    case R.id.false_radio:
                        setAnswerButton = false;
                        break;
                    default:
                        break;
                }
                inputtext = ((EditText)findViewById(R.id.add_content)).getText().toString();
            }
        });

        mYesButton = (Button) findViewById(R.id.yes_button);
        mYesButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Question q = new Question(inputtext,setAnswerButton);
                AddProblemAnswer(q);
                finish();
            }
        });
    }

    private  void AddProblemAnswer(Question isAnswerShown){
        Intent data = new Intent();
        data.putExtra(ADD_PROBLEM_ANSWER, isAnswerShown);
        setResult(RESULT_OK, data);
    }
}